﻿Public Class dlgOption
    Private Sub dlgOption_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '多国语言
        MultiLanguage()
        '加载语言文件
        For Each mFile As String In IO.Directory.GetFiles(Application.StartupPath & "\Language")
            Me.cmbMultiLanguage.Items.Add(mFile.Replace(Application.StartupPath & "\Language\", "").Replace(".xml", ""))
        Next
        cmbMultiLanguage.Text = DefaultConfig.MultiLanguage.ToString
        '编码
        For Each EnumName As String In [Enum].GetNames(GetType(EnumEncoding))
            cmbEnCoding.Items.Add(EnumName)
        Next
        cmbEnCoding.Text = DefaultConfig.CurrentEncoding.ToString
        'TAB和Space的变换
        NudSpaceForTab.Value = DefaultConfig.SpaceForTab
        '代码配置
        For Each mFile As String In IO.Directory.GetFiles(Application.StartupPath & "\CodeConfig")
            Me.cmbDefaultCodeConfig.Items.Add(mFile.Replace(Application.StartupPath & "\CodeConfig\", "").Replace(".xml", ""))
        Next
        cmbDefaultCodeConfig.Text = DefaultConfig.DefaultCodeConfig

        '日期时间
        txtDateFormat.Text = DefaultConfig.DateFormat
        txtTimeFormat.Text = DefaultConfig.TimeFormat

    End Sub
    Private Sub OK_Click() Handles MyYesCancelPanel.OK_Clicked
        With DefaultConfig
            '加载语言文件
            .MultiLanguage = cmbMultiLanguage.Text
            '编码
            .CurrentEncoding = cmbEnCoding.SelectedIndex
            'TAB和Space的变换
            .SpaceForTab = NudSpaceForTab.Value
            '代码配置
            .DefaultCodeConfig = cmbDefaultCodeConfig.Text
            '日期时间
            .DateFormat = txtDateFormat.Text
            .TimeFormat = txtTimeFormat.Text
        End With
        LanguageDoc.Load(Application.StartupPath & "\Language\" & cmbMultiLanguage.Text & ".xml")
        WriteObjectToXMLFile(DefaultConfig, GetType(Config), Application.StartupPath & "\Config.xml")
        Me.DialogResult = Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub
    ''' <summary>
    ''' 多国语言
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub MultiLanguage()
        grpCommon.Text = GetTextInLanguageDoc("Common", TextMode.Text)
        lblMultiLanguage.Text = GetTextInLanguageDoc("MultiLanguage", TextMode.Text)
        lblEncoding.Text = GetTextInLanguageDoc("Encoding", TextMode.Text)

        grpEdit.Text = GetTextInLanguageDoc("Edit", TextMode.Text)
        lblSpaceForTab.Text = GetTextInLanguageDoc("SpaceForTab", TextMode.Text)
        lblDefaultCodeConfig.Text = GetTextInLanguageDoc("DefaultCodeConfig", TextMode.Text)
        lblDateFormat.Text = GetTextInLanguageDoc("DateFormat", TextMode.Text)
        lblTimeFormat.Text = GetTextInLanguageDoc("TimeFormat", TextMode.Text)

        MyYesCancelPanel.OK_Text = GetTextInLanguageDoc("OK", TextMode.Text)
        MyYesCancelPanel.NO_Text = GetTextInLanguageDoc("Cancel", TextMode.Text)

    End Sub
    Private Sub Cancel_Click() Handles MyYesCancelPanel.NO_Clicked
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub
    Private Sub txtDateFormat_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtDateFormat.TextChanged
        Try
            Me.lblDatePreView.Text = Format(Now, txtDateFormat.Text)
        Catch ex As Exception
            Me.txtDateFormat.Text = "yyyy-MM-dd"
        End Try
    End Sub
    Private Sub txtTimeFormat_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTimeFormat.TextChanged
        Try
            Me.lblTimePreView.Text = Format(Now, txtTimeFormat.Text)
        Catch ex As Exception
            Me.txtTimeFormat.Text = "HH:mm:ss"
        End Try
    End Sub
End Class